package com.itheima.demo1;

public class Demo21MethodArray {
    //遍历数组方法
    public static void arrayPrint(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == (arr.length - 1)) {
                System.out.println(arr[i] + "]");
            } else {
                System.out.print(arr[i] + ",");
            }
        }
//        System.out.println("]");
    }

    //数组最大值的方法
    public static int[] array(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        int[] array = {max, min};
        return array;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 5, 4};
        arrayPrint(arr);
        System.out.println(array(arr)[0]);
        System.out.println(array(arr)[1]);

    }
}
